package com.haiheng.voiceandbook.BookRepository

import com.haiheng.voiceandbook.common.BaseDto
import com.haiheng.voiceandbook.common.DeviceInfoDto
import com.it.bannner.api.ApiService
import com.it.bannner.common.DownRecor
import com.it.bannner.dao.DownDao
import com.it.bannner.log.LogWriter
import okhttp3.ResponseBody

class Repository(val dao: DownDao) {
    private val TAG = "Repository"

    // 获取视频
    suspend fun getVideo(type: Int,code: String): BaseDto<MutableList<String>> {
        LogWriter.e("请求刷新视频  ${type}")
        val result = ApiService.apiService.getVideo(type,code);
        LogWriter.e("拿到结果 ${result}")
        return result
    }


    // 下载视频
    suspend fun downLoadVideo(path: String): ResponseBody {
        return ApiService.apiService.downLoadVideo(path)
    }

    // 获取设备信息
    suspend fun getDeviceInfo(code: String, type: Int): BaseDto<DeviceInfoDto> {
        LogWriter.e("请求获取设备信息 ${code} and ${type}")
        return ApiService.apiService.getDeviceInfo(code, type)
    }

    suspend fun queryList(): List<DownRecor> {
        return dao.queryList()
    }

    suspend fun addRecord(recor: DownRecor) {
        return dao.addRecord(recor)
    }

    suspend fun deleteRecord(recor: DownRecor) {
        return dao.deleteRecord(recor)
    }

    suspend fun updateRecord(recor: DownRecor) {
        return dao.updateRecord(recor)
    }

    suspend fun queryListByName(name: String): DownRecor {
        return dao.queryListByName(name)
    }

    suspend fun deleteAll() {
        return dao.deleteAll()
    }
}